#include "CG_flip_flop.h"

using namespace std;
short CG_flip_flop::R;

CG_flip_flop::CG_flip_flop()
{
	this->ID = FF_UNDEFINED;
	this->my_loc.set_x(LOCATION_UNDEFINED);
	this->my_loc.set_y(LOCATION_UNDEFINED);
}

CG_flip_flop::CG_flip_flop(const unsigned long new_ID, const float loc_x, const float loc_y, const char *vector, const string& aName)
{
	if(new_ID < 0)
	{
		this->ID = FF_UNDEFINED;
	}
	else
	{
		this->ID = new_ID;
	}

	this->name = aName;
	
	this->my_loc.set_x(loc_x);
	this->my_loc.set_y(loc_y);
	
	toggle_vec.CG_toggle_vector_set_data(vector);
}


CG_flip_flop::CG_flip_flop(const unsigned long new_ID, const float loc_x, const float loc_y, const string& aName)
{
	if(new_ID < 0)
	{
		this->ID = FF_UNDEFINED;
	}
	else
	{
		this->ID = new_ID;
	}

	this->name = aName;
	
	this->my_loc.set_x(loc_x);
	this->my_loc.set_y(loc_y);
}


CG_flip_flop::CG_flip_flop(const CG_flip_flop& ff)
{
	this->ID = ff.ID;
	
	this->my_loc.set_x(ff.my_loc.get_x());
	this->my_loc.set_y(ff.my_loc.get_y());
		
	this->toggle_vec.CG_toggle_vector_set_data(ff.toggle_vec.CG_toggle_vector_get_org_data());

	this->name = ff.name;
}
		

CG_flip_flop::~CG_flip_flop()
{
}


CG_flip_flop& CG_flip_flop::operator=(const CG_flip_flop& new_ff)
{
	if(this == &new_ff)
	{
		return *this;
	}
	this->ID = new_ff.ID;

	this->my_loc.set_x(new_ff.my_loc.get_x());
	this->my_loc.set_y(new_ff.my_loc.get_y());

	this->name = new_ff.name;
	this->toggle_vec.CG_toggle_vector_set_data(new_ff.toggle_vec.CG_toggle_vector_get_org_data());

	return *this;
}
		

long CG_flip_flop::get_ID()
{
	return this->ID;
}
		

bool CG_flip_flop::set_ID(const long new_ID)
{
	if(new_ID < 0)
	{
		return false;
	}
	
	this->ID = new_ID;
	return true;
}


bool CG_flip_flop::init_vector(const char *vector)
{
	if(NULL == vector)
	{
		return false;
	}
	
	this->toggle_vec.CG_toggle_vector_set_data(vector);
	
	return true;
}
		

float CG_flip_flop::get_loc_x()
{
	return this->my_loc.get_x();
}
		

float CG_flip_flop::get_loc_y()
{
	return this->my_loc.get_y();
}
		

bool CG_flip_flop::set_loc(const float x, const float y)
{
	return (this->my_loc.set_x(x) && this->my_loc.set_y(y));
}
		

bool CG_flip_flop::set_loc(CG_location& loc)
{
	return (this->my_loc.set_x(loc.get_x()) && this->my_loc.set_y(loc.get_y()));
}
		

float CG_flip_flop::get_distance(const float x, const float y)
{
	return this->my_loc.calc_distance(x, y);
}
		

float CG_flip_flop::get_distance(const CG_location& loc)
{
	return this->my_loc.calc_distance(loc);
}
		

long CG_flip_flop::get_next_toggle(long index)
{
	return this->toggle_vec.get_next_toggle(index);
}
		

TOGGLE_BIN CG_flip_flop::operator[](long index)
{
	return this->toggle_vec[index];
}
		

long CG_flip_flop::get_vector_length()
{
	return this->toggle_vec.get_length();
}
		

long CG_flip_flop::get_num_toggles()
{
	return this->toggle_vec.get_num_toggles();
}


long CG_flip_flop::get_toggle_vector_num_elements()
{
	return this->toggle_vec.get_num_elements();
}


const string& CG_flip_flop::get_name()
{
	return this->name;
}


CG_toggle_vector CG_flip_flop::operator&(CG_flip_flop& ff)
{
	return this->toggle_vec.operator &(ff.toggle_vec);
}


CG_toggle_vector CG_flip_flop::operator|(CG_flip_flop& ff)
{
	return this->toggle_vec.operator |(ff.toggle_vec);
}
		

CG_toggle_vector CG_flip_flop::operator^(CG_flip_flop& ff)
{
	return this->toggle_vec.operator ^(ff.toggle_vec);
}

